google cloud api | test global forward | check dns | Search

The code defines a test suite with three test cases to add a subdomain to a load balancer, involving inserting a backend bucket, adding a frontend, and updating a URL map, with each test case having a 60-second timeout.

Alternatively, you can summarize it in two sentences:

The code is a test suite that adds a subdomain to a load balancer, consisting of three test cases to insert a backend bucket, add a frontend, and update a URL map. Each test case has a 60-second timeout and includes assertions to verify the returned values are not empty.

Run example

npm run import -- "test bucket web map"

test bucket web map

var assert = require('assert');
var importer = require('../Core');
var {
    insertBackendBucket,
    insertGlobalForward,
    updateUrlMap
} = importer.import("add google bucket web map");
var addIP = importer.import("check dns");
var project = 'spahaha-ea443';
var domain = 'sheet-to-web.sheet-to-web.com';
var urlMap = 'web-map';

describe('adding a subdomain to a load balancer', () => {
    it('should add a bucket backend', () => {
        return insertBackendBucket(project, domain)
            .then(bucketName => {
                assert(bucketName.length > 0, 'should have added a backend');
            })
    }).timeout(60000)
    
    it('should add a frontend to load balancer', () => {
        // TODO: check for A record in DNS to get ip
        return addIP(project, domain)
            .then(ip => insertGlobalForward(project, ip, urlMap, domain))
            .then(bucketName => {
                assert(bucketName.length > 0, 'should have added a forward');
            })
    }).timeout(60000)
    
    it('should update url map on load balancer', () => {
        return updateUrlMap(project, urlMap, domain)
            .then(map => {
                assert(map.length > 0, 'should have updated the map');
            })
    }).timeout(60000)
})

What the code could have been:

const assert = require('assert');
const importer = require('../Core');

const {
  insertBackendBucket,
  insertGlobalForward,
  updateUrlMap
} = importer.import('add google bucket web map');
const addIP = importer.import('check dns');

const project ='spahaha-ea443';
const domain ='sheet-to-web.sheet-to-web.com';
const urlMap = 'web-map';

describe('adding a subdomain to a load balancer', () => {
  // Test 1: Adding a bucket backend
  it('should add a bucket backend', async () => {
    const bucketName = await insertBackendBucket(project, domain);
    assert(bucketName.length > 0,'should have added a backend');
  }).timeout(60000);

  // Test 2: Adding a frontend to load balancer
  it('should add a frontend to load balancer', async () => {
    const ipAddress = await addIP(project, domain);
    const bucketName = await insertGlobalForward(project, ipAddress, urlMap, domain);
    assert(bucketName.length > 0,'should have added a forward');
  }).timeout(60000);

  // Test 3: Updating url map on load balancer
  it('should update url map on load balancer', async () => {
    const map = await updateUrlMap(project, urlMap, domain);
    assert(map.length > 0,'should have updated the map');
  }).timeout(60000);
});

Code Breakdown

Requirements and Imports

Variables

Test Suite

The code defines a test suite for adding a subdomain to a load balancer. It consists of three test cases:

1. Adding a Bucket Backend

2. Adding a Frontend to the Load Balancer

3. Updating the URL Map on the Load Balancer

All three test cases have a timeout of 60 seconds each.